package com.thundersoft.musicbox;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

/**
 * 备注:
 *
 * @author hmb
 * @version 1.0
 * @since 2015/11/16 10:17
 */
public class MusicService extends Service{

    private MediaPlayer player = null;
    private MusicManager musicManager = null;

    @Override
    public IBinder onBind(Intent intent) {
        return new MusicBinder(this);
    }

    @Override
    public void onCreate() {
        Log.d("MusicService","onCreate");
        super.onCreate();
        player = new MediaPlayer();
        musicManager = new MusicManager(player);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        player.release();
        player = null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    public  class MusicBinder extends Binder{
        private MusicService mService = null;

        public MusicBinder(MusicService service){
            this.mService = service;
        }
        public MusicService getService(){
            return  mService;
        }
        public MusicManager getMusicManager(){
            return musicManager;
        }
    }
}
